<template>
  <!-- <div ref="container">
    <div class="coupon-list" v-if="couponsList.length > 0">
      <div
        class="item acea-row row-center-wrapper"
        v-cloak
        v-for="(item, index) in couponsList"
        :key="index"
      >
        <div class="money" :class="item._type === 0 ? 'moneyGray' : ''">
          ￥<span class="num">{{ item.coupon_price }}</span>
        </div>
        <div class="text">
          <div class="condition line1">{{ item.coupon_title }}</div>
          <div class="data acea-row row-between-wrapper">
            <div v-if="item._end_time === 0">不限时</div>
            <div v-else>{{ item._add_time }}-{{ item._end_time }}</div>
            <div class="bnt gray" v-if="item._type === 0">{{ item._msg }}</div>
            <div class="bnt bg-color-red" v-else>{{ item._msg }}</div>
          </div>
        </div>
      </div>
    </div>
    暂无优惠券
    <div
      class="noCommodity"
      v-if="couponsList.length === 0 && loading === true"
    >
      <div class="noPictrue">
        <img src="@assets/images/noCoupon.png" class="image" />
      </div>
    </div>
  </div> -->

  <el-container>
      <el-header height="172px" style="padding:0 0;">
          <HomeNavigation></HomeNavigation>
          <SearchBox></SearchBox>
          <ClassNavigation></ClassNavigation>
      </el-header>
      <el-container class="coupon">
        <el-container style="width:1090px;margin:20px auto 0;">
            <el-aside width="180px">
                <div class="side">
                  <el-menu
                  default-active="1-1"
                  active-text-color="#b4a078"
                  @open="handleOpen"
                  @close="handleClose">
                    <el-menu-item-group>
                      <p slot="title" class="sideTitle">我的服务</p>
                      <el-menu-item index="1-1">
                         <router-link to="/user">
                          <p class="sideIetm">个人中心</p>
                        </router-link>
                        </el-menu-item>
                      <el-menu-item index="1-2">
                        <router-link to="/user/vip">
                          <p class="sideIetm">会员中心</p>
                        </router-link>
                      </el-menu-item>
                      <el-menu-item index="1-3">
                        <router-link to="/user/add_manage">
                          <p class="sideIetm">地址信息</p>
                        </router-link>
                      </el-menu-item>
                      <el-menu-item index="1-4">
                        <router-link to="/collection">
                        <p class="sideIetm">我的收藏</p>
                        </router-link>
                        </el-menu-item>
                      <el-menu-item index="1-5">
                          <router-link to="/user/user_coupon">
                            <p class="sideIetm">优惠券</p>
                          </router-link>
                      </el-menu-item>
                    </el-menu-item-group>
                    <el-menu-item-group>
                      <p slot="title" class="sideTitle">订单管理</p>
                      <el-menu-item index="2-1">
                        <router-link to="/order/list/0">
                          <p class="sideIetm">我的订单</p>
                        </router-link>
                      </el-menu-item>
                      <el-menu-item index="2-2"><router-link to="/order/refund_list"> 
                        <p class="sideIetm">售后/退款</p>
                      </router-link></el-menu-item>
                    </el-menu-item-group>
                </el-menu>
              </div>
            </el-aside>
          <el-main style="padding: 20px 0 20px 20px;">
            <div class="main">
              <div class="title">优惠券</div>
              <div class="coupon acea-row"  v-if="couponsList.length > 0">
                <div class="item acea-row "
                      v-for="(item, index) in couponsList"
                      :key="index">
                <div class="c-money">
                    ￥{{ item.coupon_price }}
                </div>
                <div class="c-text">
                  <div class="line1">{{ item.coupon_title }}</div>
                  <div  class="line2" v-if="item._end_time === 0">不限时</div>
                  <div class="line2" v-else>{{ item._add_time }}-{{ item._end_time }}</div>
                  <div class="line3 l-gray" v-if="item._type === 0">{{ item._msg }}</div>
                  <div class="line3 l-red"  v-else>{{ item._msg }}</div>
                </div>
                </div>
              </div>
              <div class="noCoupon acea-row row-center-wrapper" v-if="couponsList.length === 0 && loading === true">
                  <img src="@assets/images/noCoupon.png" alt="" class="n-image">
              </div>
            </div>
            
          </el-main>
        </el-container>
        <el-footer style="padding: 0;">
        <Foot></Foot>
          </el-footer>
      </el-container>
  </el-container>
</template>
<script>
import { getCouponsUser } from "@api/user";
import HomeNavigation from "@components/HomeNavigation";
import ClassNavigation from "@components/ClassNavigation";
import SearchBox from "@components/SearchBox";
import Foot from "@components/Foot";
const NAME = "UserCoupon";

export default {
  name: "UserCoupon",
  components: {
    HomeNavigation,
    ClassNavigation,
    SearchBox,
    Foot
  },
  props: {},
  data: function() {
    return {
      couponsList: [],
      loading: false
    };
  },
  watch: {
    $route: function(n) {
      var that = this;
      if (n.name === NAME) {
        that.getUseCoupons();
      }
    }
  },
  mounted: function() {
    this.getUseCoupons();
  },
  methods: {
    getUseCoupons: function() {
      let that = this,
        type = 0;
      getCouponsUser(type).then(res => {
        that.couponsList = res.data;
        that.loading = true;
      });
    }
  }
};
</script>

<style scoped>
    .coupon {
      background-color: #fff;
    }
    .side {
      border: 1px solid #eaeaea;
      height: 510px;
      padding-top: 24px;
      margin-top: 20px;
    }
    .side .sideTitle {
      font-size: 16px;
      color: #333;
      font-weight: 700;
      padding-left: 23px;
    }
  
     .side .sideIetm {
      font-size: 14px;
      padding-left: 23px;
    }
    .main {
      width: 890px;
      border: 1px solid #eaeaea;
    }
  .main .title {
    height: 42px;
    background-color: #f5f5f5;
    line-height: 41px;
    font-size: 14px;
    color: #333;
    font-family: "Microsoft Yahei","微软雅黑",verdana;
    padding-left: 21px;
    border-bottom: 1px solid #eaeaea;
  }
  .main .noCoupon {
    width: 888px;
    height: 532px;
  }
  .main .noCoupon .n-image {
    width: 414px;
    height: 336px;
  }
  .main  .coupon {
    width: 888px;
    padding: 20px 14px;
  }
  .main .coupon  .item {
    width: 282px;
    height: 89px;
    margin-bottom: 10px;
    background-image:url('../../../assets/images/coupon99.webp');
    background-repeat:no-repeat;
    background-size:100% 100%;
    margin: 0 1px;
    margin-bottom: 5px;
  }
  .main .coupon  .item  .c-money {
    width: 100px;
    height: 89px;
    font-size: 20px;
    line-height: 89px;
    text-align: center;
    color: #fff;
    font-weight: 700;
  }
  .main .coupon  .item  .c-text {
    width: 182px;
    height: 89px;
    padding-top: 20px;
  }
  .main .coupon  .item  .c-text .line1 {
    height: 20px;
    max-width: 160px;
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 14px;
    color: #fff;
    line-height: 20px;
  }
  .main .coupon  .item  .c-text .line2 {
    font-size: 12px;
    white-space: nowrap;
    color: #fff;
    line-height: 20px;
    overflow: hidden;
    font-family: "Microsoft Yahei","微软雅黑",verdana;
  }
  .main .coupon  .item  .c-text .line3 {
    width: 50px;
    height: 16px;
    font-size: 12px;
    line-height: 16px;
    font-family: "Microsoft Yahei","微软雅黑",verdana;
    background-color: #fff;
    text-align: center;
  }
  .main .coupon  .item  .c-text  .l-gray {
    color: #CCCCCC;
  }
  .main .coupon  .item  .c-text .l-red {
    color: #DD766C;
  }
  </style>
